﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FlowerShop.Models;
using System.Data;

namespace FlowerShop.DataAccessLayer
{
    public class CategoriesDAO
    {
        private static FlowerDBEntities db = new FlowerDBEntities();
        public static Boolean InsertCategories(CategoriesModels categoriesModel)
        {
            Category categories = Mapper.cateFromModels(categoriesModel);
            try
            {
                db.AddToCategories(categories);
                db.SaveChanges();
                return true;
            }
            catch (NullReferenceException)
            {
                return false;
            }
        }
        //Update Categories
        public static Boolean UpdateCategories(CategoriesModels categoriesModels)
        {
            try
            {
                var categories = db.Categories.Single(c => c.CateID == categoriesModels.CateId);
                var cateUpdate = Mapper.cateFromModels(categoriesModels);
                categories.CateaName = cateUpdate.CateaName;
                categories.Desription = cateUpdate.Desription;
                db.SaveChanges();
                return true;
            }
            catch (NullReferenceException)
            {
                return false;
            }

        }

        public static List<Category> GetAllCategories()
        {
            List<Category> listCate = db.Categories.ToList();
            return listCate;
        }
       
    }
}